package com.timesheet.gui.efforttracker.composite;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class FormLayoutComplex {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);

		GridLayout layout = new GridLayout(1, false);
		//FormLayout layout = new FormLayout();
		shell.setLayout(layout);

		Button btnOne = new Button(shell, SWT.PUSH);
		btnOne.setText("One");
		Button two = new Button(shell, SWT.PUSH);
		two.setText("twojjjjjj");
		FormData data = new FormData();
		//data.top = new FormAttachment(0, 5);
		//data.left = new FormAttachment(0, 5);
		//data.bottom = new FormAttachment(50, -5);
		//data.right = new FormAttachment(50, -5);
		//btnOne.setLayoutData(data);

		FontData[] fontData = btnOne.getFont().getFontData();
		for (int i = 0; i < fontData.length; ++i) {
			fontData[i].setHeight(30);
		}

		final Font newFont = new Font(display, fontData);

		btnOne.setFont(newFont);

		// Since you created the font, you must dispose it
		btnOne.addDisposeListener(new DisposeListener() {

			@Override
			public void widgetDisposed(DisposeEvent e) {
				newFont.dispose();
			}
		});

		/*Composite composite = new Composite(shell, SWT.NONE);
		composite.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_YELLOW));
		GridLayout gridLayout = new GridLayout();
		gridLayout.marginHeight = 20;
		gridLayout.marginWidth = 20;
		composite.setLayout(gridLayout);
		Button two = new Button(composite, SWT.PUSH);
		two.setText("two");
		GridData gridData = new GridData(GridData.FILL_BOTH);
		two.setLayoutData(gridData);
		Button three = new Button(composite, SWT.PUSH);
		three.setText("three");
		gridData = new GridData(GridData.FILL_HORIZONTAL);
		three.setLayoutData(gridData);
		Button four = new Button(composite, SWT.PUSH);
		Font font = four.setText("four");
		gridData = new GridData(GridData.FILL_BOTH);
		four.setLayoutData(gridData);

		//formdata for composite
		data = new FormData();
		data.top = new FormAttachment(0, 15);
		data.left = new FormAttachment(btnOne, 25);
		data.bottom = new FormAttachment(50, -15);
		data.right = new FormAttachment(100, -25);

		composite.setLayoutData(data);
		Button five = new Button(shell, SWT.PUSH);
		five.setText("five");
		data = new FormData();
		data.top = new FormAttachment(btnOne, 5);
		data.left = new FormAttachment(0, 5);
		data.bottom = new FormAttachment(100, -5);
		data.right = new FormAttachment(100, -5);
		five.setLayoutData(data);*/
		shell.pack();
		shell.open();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		display.dispose();
	}
}